package io.terminus.spzx.manager.service.impl;

import cn.hutool.core.date.DateUtil;
import io.terminus.spzx.manager.mapper.OrderStatisticsMapper;
import io.terminus.spzx.manager.service.OrderInfoService;
import io.terminus.spzx.model.dto.order.OrderStatisticsDto;
import io.terminus.spzx.model.entity.order.OrderStatistics;
import io.terminus.spzx.model.vo.order.OrderStatisticsVo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * @Author lichunlong lcl253137@alibaba-inc.com
 * @Desc 订单管理Service实现类
 * @Date 2024-10-15
 */
@Service
@RequiredArgsConstructor
public class OrderInfoServiceImpl implements OrderInfoService {

    private final OrderStatisticsMapper orderStatisticsMapper;

    @Override
    public OrderStatisticsVo getOrderStatisticsData(OrderStatisticsDto orderStatisticsDto) {
        // 查询统计结果
        List<OrderStatistics> orderStatisticsList = orderStatisticsMapper.selectList(orderStatisticsDto);

        //日期列表
        List<String> dateList = orderStatisticsList.stream().map(orderStatistics -> DateUtil.format(orderStatistics.getOrderDate(), "yyyy-MM-dd")).toList();
        //统计金额列表
        List<BigDecimal> amountList = orderStatisticsList.stream().map(OrderStatistics::getTotalAmount).toList();

        return new OrderStatisticsVo(dateList, amountList);
    }
}
